// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
/* eslint-disable*/






import Vue from 'vue'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import App from './App'
import Nofound from './components/nofound'

//赛事列表
import raceList from './components/racelist'
//新闻列表
import newList from './components/newlist'
//报名页面
import signUp from './components/sign_up'

import Index from './components/index'
import List from './components/list'
import Disclaimer from './components/disclaimer'
import Certificate from './components/certificate'
import Form from './components/form'
import Timeline from './components/timeline'
import PayDetails from './components/payDetails'
import Procedure from './components/procedure'
import Declare from './components/declare'
import Invite from './components/invite'
import HistoryScore from './components/historyScore'
import Modify from './components/modify'
import Useinvite from './components/useinvite'
import Share from './components/share'

import Index1 from './components/index'
import Races from './components/races'
import Test from './components/test'
import Demo from './components/demo'
import Login from './components/login'
import Report from './components/report'
import Password_find from './components/password_find'
import Register from './components/register'
import Login_phone from './components/login_phone'
import New_detail from './components/new_detail'
import User from './components/user'
import Messagedetail from './components/messagedetail'
import ImproveUserInformation from './components/improve_user_information'
import Teamlist from './components/teamlist'
import Createteam from './components/createteam'
import Query from './components/query'




import User_racelist from './components/user_racelist'
import Photolist from './components/photolist'
import Photo from './components/photo'
import Reportlist from './components/reportlist'

// 九宫格
import Message from './components/message'

import Fqa from './components/fqa'
import Credential from './components/credential'


import Identity from '@/common/components/identity'
import Number from '@/common/components/number'
import EBank from '@/common/components/e_bank'
import ThirdParty from '@/common/components/third_party'
import myFile from '@/common/components/myfile'

/*

 /!*页面加载开始*!/
 const Nofound=(resolve)=>{
 import('./components/nofound').then((module) => {
 resolve(module)
 })
 }

 const List=(resolve)=>{
 import('./components/list').then((module) => {
 resolve(module)
 })
 }

 const Disclaimer=(resolve)=>{
 import('./components/disclaimer').then((module) => {
 resolve(module)
 })
 }

 const Certificate=(resolve)=>{
 import('./components/certificate').then((module) => {
 resolve(module)
 })
 }

 const Form=(resolve)=>{
 import('./components/form').then((module) => {
 resolve(module)
 })
 }


 const Pay=(resolve)=>{
 import('./components/pay').then((module) => {
 resolve(module)
 })
 }

 /!*页面加载结束*!/

 /!*组件加载开始*!/
 const Identity=(resolve)=>{
 import('@/common/components/identity').then((module) => {
 resolve(module)
 })
 }

 const Number=(resolve)=>{
 import('@/common/components/number').then((module) => {
 resolve(module)
 })
 }

 const EBank=(resolve)=>{
 import('@/common/components/e_bank').then((module) => {
 resolve(module)
 })
 }

 const ThirdParty=(resolve)=>{
 import('@/common/components/third_party').then((module) => {
 resolve(module)
 })
 }

 /!*组件加载结束*!/
 */

const base = ''

import '@/common/css/index.less'
import 'element-ui/lib/theme-chalk/index.css'


import {
  LoadingPlugin,
  ConfigPlugin
} from 'vux'


import VueI18n from 'vue-i18n'


import {
  cookie
} from 'vux'


Vue.use(VueRouter)
Vue.use(VueI18n)
Vue.use(LoadingPlugin)


const routes = [{
    path: '*',
    component: raceList
  },{
    path:'/share',
    component: Share
  }, {
    path: '/query',
    component: Query
  }, {
    path: '/baoming',
    component: Index
  }, {
    path: '/index',
    component: raceList
  }, {
    path: '/useinvite',
    component: Useinvite
  },
  {
    path: '/improve_user_information',
    component: ImproveUserInformation
  }, {
    path: '/createteam',
    component: Createteam
  }, {
    path: '/teamlist',
    component: Teamlist,
  }, {
    path: '/messagedetail',
    component: Messagedetail,
    name: 'messagedetail'
  }, {
    path: '/reportlist',
    component: Reportlist
  }, {
    path: '/user_racelist',
    component: User_racelist,
  }, {
    path: '/photo',
    component: Photo,
  }, {
    path: '/photolist',
    component: Photolist,
  }, {
    path: '/user',
    component: User,
  }, {
    path: '/userinfo',
    component: User,
  }, {
    path: '/userinfo/editname',
    component: User,
  }, {
    path: '/userinfo/editportrait',
    component: User,
  }, {
    path: '/demo',
    component: Demo,
  }, {
    path: '/new_detail',
    component: New_detail
  }, {
    path: '/register',
    component: Register
  }, {
    path: '/login_phone',
    component: Login_phone
  },
  {
    path: '/password_find',
    component: Password_find
  },
  {
    path: '/login',
    component: Login,
  }, {
    path: '/report',
    component: Report,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  },
  {
    path: '/',
    component: Index,
  },
  {
    path: '/signup',
    component: signUp,
  },
  {
    path: '/newlist',
    component: newList,
  },
  {
    path: '/racelist',
    component: raceList,
  },
  {
    path: '/test',
    component: Test,
  },
  {
    path: '/list',
    component: List,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  },
  {
    path: '/races',
    component: Races,
  },
  {
    path: '/bind',
    component: Index1,
  },
  {
    path: '/declare',
    component: Declare,
    name: 'declare',
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  },
  {
    path: '/disclaimer',
    component: Disclaimer,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  },
  {
    path: '/certificate',
    component: Certificate,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    },
    children: [{
      path: '/certificate/',
      redirect: 'identity'
    }, {
      path: '/certificate/identity',
      name: 'Identity',
      component: Identity
    }, {
      path: '/certificate/number',
      name: 'Number',
      component: Number
    }]
  },
  {
    path: '/form',
    component: Form,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    },
    name: 'form'
  },
  {
    path: '/message',
    component: Message,
    name: 'message',
  },
  {
    path: '/photo',
    component: Photo,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  },
  {
    path: '/credential',
    component: Credential,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  },
  {
    path: '/fqa',
    component: Fqa,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  },
  {
    path: '/timeline',
    component: Timeline,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  }, {
    path: '/detail',
    component: PayDetails
  }, {
    path: '/payDetails',
    component: PayDetails
  }, {
    path: '/payDetail',
    component: PayDetails
  },
  {
    path: '/procedure',
    component: Procedure,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  },
  {
    path: '/invite/',
    component: Invite,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  },
  {
    path: '/invite/*',
    component: Invite,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  }, {
    path: '/historyScore',
    name: 'historyScore',
    component: HistoryScore,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    }
  }, {
    path: '/modify',
    component: Modify,
    meta: {
      requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
    },
    name: 'modify'
  }
]

const router = new VueRouter({
  mode: 'hash',
  routes
});


//cookie mock!!!
//cookie.set('HUIPAO_SID', 123)

//写入全部变量raceidRACEID
//Vue.prototype.RACEID = window.pageConfig.raceid;
//全局获取raceInfo
import {
  host
} from "@/api/config.js";
import {
  raceShow
} from "@/api/raceshow.js";
import {
  indexedDB
} from "@/api/indexedDB.js";
router.beforeEach((to, from, next) => {
  //获取indexedDB存在的数据raceInfo,
  // indexedDB('raceInfo', 'get', window.pageConfig.raceid, '', function (a) {
  //   if (!a) {
  //     raceShow(`${host}race/show`, {
  //       raceid: window.pageConfig.raceid
  //     }).then(response => {
  //       if (response.data.code == 200) {
  //         let data = response.data.data
  //         indexedDB('raceInfo', 'set', window.pageConfig.raceid, data, function () {

  //         });
  //         indexedDB('disclaimer', 'set', window.pageConfig.raceid, data.disclaimer, function () {});
  //         next();
  //       }
  //     });
  //   } else {
  //     indexedDB('disclaimer', 'set', window.pageConfig.raceid, a.disclaimer, function () {});
  //     next();
  //   }
  // }.bind(this));


  next();

  /* if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
   if (cookie.get('HUIPAO_SID')) {  // 通过vuex state获取当前的token是否存在
   next();
   }
   else {
   window.location.href = 'http://ihuipao.com/login'
   }
   }*/

})


const i18n = new VueI18n({
  locale: 'ZH', // 语言标识
  messages: {
    'ZH': require('./common/locales/lang/zh'), // 中文语言包
    'EN': require('./common/locales/lang/en'), // 英文语言包
    'TW': require('./common/locales/lang/tw') // 繁体语言包
  }
})

// 设置语言包

if (document.querySelector('html').lang == 'zh-cn') {
  i18n.locale = 'ZH'
} else if (document.querySelector('html').lang == 'tw') {
  i18n.locale = 'TW'
} else if (document.querySelector('html').lang == 'en') {
  i18n.locale = 'EN'
} else {
  i18n.locale = 'ZH'
}

//i18n.locale = 'EN'

FastClick.attach(document.body)

Vue.config.productionTip = false


/* eslint-disable no-new */
new Vue({
  router,
  i18n,
  render: h => h(App)
}).$mount('#app-box')
